import java.util.HashSet;
import java.util.Set;

public class LC_202 {
    public boolean isHappy(int n) {
        Set<Integer> set = new HashSet<>();
        int count = 0;
        int key = n;
        while(count != 1){
            count = 0;
            while(key > 0){
                count += (key%10) * (key%10);
                key /= 10;
            }
            if(set.contains(count) == true){
                return false;
            }
            set.add(count);
            key = count;
        }
        return true;
    }
}
